#coding:utf-8

from models import Devlog
from google.appengine.api import users
import os
import datetime
import PyRSS2Gen
import re
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class PublicPage(webapp.RequestHandler):
    def render(self, template_file, template_value):
        path = os.path.join(os.path.dirname(__file__), template_file)
        self.response.out.write(template.render(path, template_value))
    
    def error(self,code):
        if code==400:
            self.response.set_status(code)
        else:
            self.response.set_status(code)
            
    def is_admin(self):
        return users.is_current_user_admin()
    
    def head(self, *args):
        return self.get(*args) 
    
class About(PublicPage):
    def get(self):

        user = users.get_current_user()

        devlogs = Devlog.all().order('-createtime')
              
        template_value={"user": user,
                        'devlogs': devlogs,
                        'login_url': users.CreateLoginURL(self.request.uri),
                        'logout_url': users.CreateLogoutURL(self.request.uri),
                        }
        self.render('template/about.html', template_value)

def main():
  webapp.template.register_template_library('filter')
  application = webapp.WSGIApplication(
                                     [('/about', About),
                                      ],
                                     debug=True)
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
